package com.dongdongshop.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradeFastpayRefundQueryRequest;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.request.AlipayTradeQueryRequest;
import com.alipay.api.request.AlipayTradeRefundRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class BeanConfig {

    @Autowired
    private AlipayConfig alipayConfig;

    @Bean
    public AlipayClient alipayClient(){
        return new DefaultAlipayClient(alipayConfig.getGatewayUrl(), alipayConfig.getApp_id(), alipayConfig.getMerchant_private_key(), alipayConfig.getFormate(), alipayConfig.getCharset(), alipayConfig.getAlipay_public_key(), alipayConfig.getSign_type());
    }

    @Bean
    public AlipayTradePagePayRequest alipayRequest(){
        AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
        alipayRequest.setReturnUrl(alipayConfig.getReturn_url());
        alipayRequest.setNotifyUrl(alipayConfig.getNotify_url());
        return alipayRequest;
    }

    @Bean
    public AlipayTradeQueryRequest alipayTradeQueryRequest(){
        return new AlipayTradeQueryRequest();
    }

    @Bean
    public AlipayTradeRefundRequest alipayTradeRefundRequest(){
        return new AlipayTradeRefundRequest();
    }

    @Bean
    public AlipayTradeFastpayRefundQueryRequest alipayTradeFastpayRefundQueryRequest(){
        return new AlipayTradeFastpayRefundQueryRequest();
    }
}
